package com.kfm.jdbc.day0404.thread;

import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;

public class Demo03 {

    public static void main(String[] args) {
        MyCallable callable = new MyCallable();

        // 创建线程
        FutureTask<Integer> futureTask = new FutureTask<>(callable);
        Thread thread = new Thread(futureTask);

        thread.start();

        try {
            // main 线程阻塞, 等待 callable 线程执行完毕, 返回结果
            Integer integer = futureTask.get();
            System.out.println(integer);
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        } catch (ExecutionException e) {
            throw new RuntimeException(e);
        }

        for (int i = 0; i < 10; i++) {
            System.out.println(Thread.currentThread().getName() + i);
        }
    }
}
